package lib.bone.audit.workload.service;

import lib.bone.audit.domain.vo.FlowWorkLinkVO;
import lib.bone.audit.workload.domain.NepuWorkload;
import lib.bone.audit.workload.domain.dto.AnalysisUserWorkloadDTO;
import lib.bone.audit.workload.domain.dto.DistributeDTO;
import lib.bone.audit.workload.domain.dto.WorkloadCountVO;
import lib.bone.audit.workload.domain.vo.*;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.common.service.BaseService;
import lib.bone.flow.domain.entity.FlowWork;
import lib.bone.system.domain.vo.UserBaseVO;
import org.springframework.data.domain.Example;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

public interface NepuWorkloadService extends BaseService<NepuWorkload,String> {

    /**
     * 获取本周期全部工作量记录 含 教学子周期
     * @return
     */
    List<NepuWorkload> getNowWorkload(String userId,List<String> subIds);

    List<NepuWorkload> getByLinkIds(List<String> linkIds);


    /**
     * 将符合 example 条件的工作量记录，全部转化为薪酬
     * @param example
     * @param useMethod
     * @return
     */
    double convertSalary(Example<NepuWorkload> example,String useMethod);


    double convertSalary(List<NepuWorkload> list,String useMethod);



    /**
     * 构建服务名
     */
    void buildAwardDictName(NepuWorkload workload);

    /**
     * 构建父周期信息
     */
    void buildParentCycleId(NepuWorkload workload);

    /**
     * 根据id列表获取记录
     * @param ids
     * @return
     */
    List<NepuWorkload> getByIds(List<String> ids);

    /**
     * 批量写入
     * @param workloads
     */
    void batchSave(List<NepuWorkload> workloads);

    public void fixWorkload(NepuWorkload nepuWorkload);



        List<NepuWorkload> getAll();

    /**
     * 核验流程实例状态和工作量状态
     * @param flowWork
     * @return
     */
    Future<FlowWorkLinkVO> checkFlowWorkWithWorkload(FlowWork flowWork);



    Future<AnalysisUserWorkloadDTO> AnalysisUserWorkload(Long userId);

//    Future<List<WorkloadExport>>

    /**
     * 工作量导出 分析
     * @param baseVO
     * @return
     */
    Future<List<WorkloadExportVO>> UserWorkloadAnalysisV2(UserBaseVO baseVO,String deptName,String postType,String postGrade,String postLevel);

    FinalWorkloadExportVO performanceAnalysis(UserBaseVO baseVO, String deptName, String postType, String postGrade, String postLevel,
                                                                       Double targetT,Double targetR,Double standard);

    Future<List<TeachWorkloadExportVO>> UserTeachWorkload(UserBaseVO baseVO, String deptName, String postType, String postGrade, String postLevel);

    /**
     * 按类别导出工作量
     * @param baseVO
     * @return
     */
    Future<List<TypeExportVO>> WorkloadType(UserBaseVO baseVO, String deptName, String postType, String postGrade, String postLevel);

    Future<List<TypeExportXVO>> WorkloadTypeX(UserBaseVO baseVO, String deptName, String postType, String postGrade, String postLevel);

    List<TopicExportVO> topicData();

//    @Deprecated
//    Future<UserWorkloadDTO> UserWorkload(Long userId);

    /**
     * 科研工作量抵扣
     * @param userId
     */
    @Deprecated
    void researchDeduction(Long userId,Double needWorkload);

    /**
     * 教学工作量抵扣
     * @param userId
     */
    @Deprecated
    void teachDeduction(Long userId,Double needWorkload);




    double deduction(List<NepuWorkload> list, Double needWorkload, String useMethod,String postType);

    /**
     * 用Example 查询并且抵扣
     * @param example
     * @param needWorkload
     * @param useMethod
     * @return
     */
    double deduction(Example<NepuWorkload> example, Double needWorkload,String useMethod,String postType);

    /**
     * 全量 Example 查询 & 排序
     * @param example
     * @return
     */
    List<NepuWorkload> finAll(Example<NepuWorkload> example);

    /**
     *
     * 使用 findAll(Example e) 进行替换
     * @param example
     * @return
     */
    List<NepuWorkload> getExampleWorkloads(Example<NepuWorkload> example);


    /**
     * 根据关联ID 统计
     * @param linkId
     * @return
     */
    @Deprecated
    Integer countByLinkId(String linkId);

    /**
     * 根据关联ID 获取实体信息
     * @param linkId
     * @return
     */
    Optional<NepuWorkload> getLinkEntity(String linkId);

    /**
     * 根据 实体ID查询
     */
    List<NepuWorkload> getLinkList(String mapperId);


    List<NepuWorkload> findByLinkId(String linkId);


    /**
     * 批量删除
     */
    void batchDelete(List<String> ids);

    /**
     * 获取教学和其它工作量
     */
    List<NepuWorkload> findTeachAndOther(Long userId,Integer usedUp,String cycleId);


    /**
     * 批量写入
     */
    public ResponseDTO saveList(List<NepuWorkload> list);


    /**
     * 工作量分配
     */
    public ResponseDTO distributeWorkload(DistributeDTO dto, NepuWorkload nepuWorkload);

    /**
     * 工作量获取统计
     * @param type
     * @param userId
     * @param usedUp
     * @return
     */
    public WorkloadCountVO buildWorkloadCount(String type, Long userId, Integer usedUp);


    /**
     * 使用 getLinkEntity 替换
     * @param id
     * @return
     */
    @Deprecated
    public Optional<NepuWorkload> getAccessEntity(String id);

    /**
     * 统计周期提交 -- 可以使用 findAll(Example e) 计算 size
     * @param userId
     * @param researchType
     * @param cycleId
     * @return
     */
//    @Deprecated
    public Integer countByUserIdAndResearchTypeAndCycleId(Long userId,String researchType,String cycleId);

    public List<NepuWorkload> getByUserIdAndResearchTypeAndCycleId(Long userId,String researchType,String cycleId);


}
